import { faker } from '@faker-js/faker';
import { PlayerSignup } from 'src/modules/player-signup/entities/player-signup.entity';

// 定义 PlayerSignup 的可选参数类型
type PartialPlayerSignup = Partial<PlayerSignup>;

// 生成单个 PlayerSignup 模拟数据的函数，允许传入部分数据
export function generatePlayerSignupMock(
  override?: PartialPlayerSignup,
): PlayerSignup {
  const playerSignup = new PlayerSignup();
  playerSignup.id = override?.id ?? faker.number.int();
  playerSignup.name = override?.name ?? faker.person.fullName();
  playerSignup.phone = override?.phone ?? faker.phone.number();
  playerSignup.email = override?.email ?? faker.internet.email();
  playerSignup.idCard = override?.idCard ?? faker.string.alphanumeric(18);
  playerSignup.age = override?.age ?? faker.number.int({ min: 18, max: 60 });
  playerSignup.gender = override?.gender ?? faker.person.sexType();
  playerSignup.address = override?.address ?? faker.location.streetAddress();
  playerSignup.organization = override?.organization ?? faker.company.name();
  playerSignup.eventId = override?.eventId ?? faker.number.int();
  playerSignup.stageEventId = override?.stageEventId ?? faker.number.int();
  playerSignup.createBy = override?.createBy ?? faker.number.int();
  playerSignup.createTime = override?.createTime ?? faker.date.past();
  playerSignup.updateBy = override?.updateBy ?? faker.number.int();
  playerSignup.updateTime = override?.updateTime ?? faker.date.recent();
  playerSignup.pairName = override?.pairName ?? faker.company.name();
  playerSignup.isMainPlayer =
    override?.isMainPlayer ?? faker.datatype.boolean();
  playerSignup.parentPlayerId = override?.parentPlayerId ?? faker.number.int();
  playerSignup._order =
    override?._order ?? (faker.number.int({ min: -1, max: 100 }) || null);

  // 由于 Event 和 StageEvent 未模拟，这里先设为 undefined
  playerSignup.event = override?.event ?? undefined;
  playerSignup.stageEvent = override?.stageEvent ?? undefined;
  playerSignup.parentPlayerSignup = override?.parentPlayerSignup ?? undefined;
  playerSignup.subPlayerSignups = override?.subPlayerSignups ?? [];

  return playerSignup;
}

// 生成多个 PlayerSignup 模拟数据的函数
export function generatePlayerSignupMocks(
  count: number,
  overrides?: PartialPlayerSignup[],
): PlayerSignup[] {
  return Array.from({ length: count }, (_, index) =>
    generatePlayerSignupMock(overrides?.[index]),
  );
}
